package org.grayrabbit.cms.util;

import java.io.File;
import java.io.InputStream;

import javax.activation.FileTypeMap;
import javax.activation.MimetypesFileTypeMap;

import org.grayrabbit.cms.utils.ClassLoaderUtils;


public class FileTypeUtil {
	private static FileTypeMap fileTypeMap;

	  public static String getContentType(String fileName)
	  {
	    return fileTypeMap.getContentType(fileName.toLowerCase());
	  }

	  public static String getContentType(File file)
	  {
	    return fileTypeMap.getContentType(file);
	  }

	  static
	  {
	    InputStream mimeTypesStream = ClassLoaderUtils.getResourceAsStream("mime.types", FileTypeUtil.class);
	    fileTypeMap = new MimetypesFileTypeMap(mimeTypesStream);
	  }
}
